<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="div">
        <button id="btn">点击</button>
    </div>
    <script>
        // 事件冒泡 顺序 btn => div => body
        // 事件捕获 顺序 body => div => btn
        // 事件流：事件捕获 => 事件目标 => 事件冒泡 
        const btn = document.getElementById('btn')
        const div = document.getElementById('div')
        btn.addEventListener('click', btnClick, true)
        div.addEventListener('click', divClick, true)
        function btnClick(e) {
            console.log(e.target)
            console.log('btn被点击了')
            // debugger
        }

        function divClick() {
            console.log('div被点击了')
            // debugger
        }

        function bodyClick() {
            console.log('body被点击了')
        }
    </script>
</body>
</html>